#include<bits/stdc++.h>
#define int long long
#define N 20
using namespace std;
int n,m;
int a[N],b[N];
int mx,mn=1e18;
int f[N][5505];
const int mod=998244353;
int Pow(int x,int y){
    x%=mod;
    int z=1;
    while(y){
        if(y&1) z=z*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return z;
}
void sub1(){
    printf("%lld\n",Pow(a[1],m));
}
void sub2(){
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int k=0,l=1;k<=b[i]&&j+k<=m;k++,l=l*a[i]%mod){
                f[i][j+k]=(f[i][j+k]+f[i-1][j]*l%mod)%mod;
            }
        }
    }
    printf("%lld\n",f[n][m]);
}
void sub3(){
    int l=min(m,b[1]),r=m-min(m,b[2]);
    int s=Pow(a[1],l)*Pow(a[2],m-l)%mod;
    int o=a[2]*Pow(a[1],mod-2)%mod;
    printf("%lld\n",s*((Pow(o,l-r+1)-1+mod)%mod*Pow(o-1+mod,mod-2)%mod)%mod);
}
signed main(){
    freopen("yt.in","r",stdin);
    freopen("yt.out","w",stdout);
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++) scanf("%lld %lld",&a[i],&b[i]),mx=max(mx,b[i]),mn=min(mn,b[i]);
    if(n==1){sub1();return 0;}
    if(mx<=300){sub2();return 0;}
    if(n<=2){sub3();return 0;}
    return 0;
}